import { createRouter, createWebHashHistory } from "vue-router";
/**
 * createWebHistory: 路由history模式，核心就是使用historyAPI
 * createWebHashHistory：路由hash模式，核心是根据url的hash值变化来实现的
 */
import { getCookie } from "@/utils/cookie";
import routes from "./routes";

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// 路由守卫
router.beforeEach((to, from, next) => {
  const token:string | undefined = getCookie('userId');
  if(!token && to.path !== '/login') {
    next('/login')
  }else {
    next()
  }
});
export default router;